/* Copyright (c) Colorado School of Mines, 2010.*/
/* All rights reserved.                       */

/* TABPLOT: $Revision: 1.4 $ ; $Date: 94/03/14 14:19:45 $	*/

/*********************** self documentation **********************/
/************************************************************************** 
TABPLOT - TABPLOT selected sample points on selected trace

tabplot		tabplot selected sample points on selected trace

*************************************************************************** 
Function Prototype:
void tabplot(segy *tp, int itmin, int itmax);

*************************************************************************** 
Input:
tp		pointer to a segy
itmin		minimum time sample printed
itmax		maximum time sample printed

*************************************************************************** 
Authors: CWP: Brian Sumner, Jack K. Cohen
**************************************************************************/
/**************** end self doc ********************************/

#include "su.h"
#include "segy.h"



#define SCREENFUL	19
#define PLOTWIDTH	29

cwp_String str[] = {
	"-----------------------------|",
	" ----------------------------|",
	"  ---------------------------|",
	"   --------------------------|",
	"    -------------------------|",
	"     ------------------------|",
	"      -----------------------|",
	"       ----------------------|",
	"        ---------------------|",
	"         --------------------|",
	"          -------------------|",
	"           ------------------|",
	"            -----------------|",
	"             ----------------|",
	"              ---------------|",
	"               --------------|",
	"                -------------|",
	"                 ------------|",
	"                  -----------|",
	"                   ----------|",
	"                    ---------|",
	"                     --------|",
	"                      -------|",
	"                       ------|",
	"                        -----|",
	"                         ----|",
	"                          ---|",
	"                           --|",
	"                            -|",
      	"                             *",
      	"                             |+",
      	"                             |++",
      	"                             |+++",
      	"                             |++++",
      	"                             |+++++",
      	"                             |++++++",
      	"                             |+++++++",
      	"                             |++++++++",
      	"                             |+++++++++",
      	"                             |++++++++++",
      	"                             |+++++++++++",
      	"                             |++++++++++++",
      	"                             |+++++++++++++",
      	"                             |++++++++++++++",
      	"                             |+++++++++++++++",
      	"                             |++++++++++++++++",
      	"                             |+++++++++++++++++",
      	"                             |++++++++++++++++++",
      	"                             |+++++++++++++++++++",
      	"                             |++++++++++++++++++++",
      	"                             |+++++++++++++++++++++",
      	"                             |++++++++++++++++++++++",
      	"                             |+++++++++++++++++++++++",
      	"                             |++++++++++++++++++++++++",
      	"                             |+++++++++++++++++++++++++",
      	"                             |++++++++++++++++++++++++++",
      	"                             |+++++++++++++++++++++++++++",
      	"                             |++++++++++++++++++++++++++++",
      	"                             |+++++++++++++++++++++++++++++",
};


void tabplot(segy *tp, int itmin, int itmax)
{
	float amp;	/* largest abs(datum) in window		*/
	float val;	/* temp for data value			*/
	int plt;	/* scaled data value			*/
	int i;		/* counter				*/

	amp = ABS(tp->data[itmin]);
	for (i = itmin + 1; i <= itmax; i++) {
		amp = MAX(amp, ABS(tp->data[i]));
	}

	if (amp == 0.0) { /* data all zeroes, plot zero string */
		for (i = itmin; i <= itmax; i++) {
			val = 0.0;
			printf("%5d %11.4e%s\n", i + 1, val, str[PLOTWIDTH]);
		}
	} else { /* usual case, plot scaled data */
		for (i = itmin; i <= itmax; i++) {
			val = tp->data[i];
			plt = PLOTWIDTH * (val/amp + 1.0);
			printf("%5d %11.4e%s\n", i + 1, val, str[plt]);
		}
	}

	return;
}
